<template>
  <view class="header">
    <view class="left" @click="goBack" v-if="showBack">
      <text class="back-icon">←</text>
    </view>
    <view class="title">
      <text>{{ title }}</text>
    </view>
    <view class="right">
      <slot name="right"></slot>
    </view>
  </view>
</template>

<script>
export default {
  name: "PageHeader",
  props: {
    title: {
      type: String,
      default: "标题",
    },
    showBack: {
      type: Boolean,
      default: true,
    },
  },
  methods: {
    goBack() {
      uni.navigateBack({
        delta: 1,
      });
    },
  },
};
</script>

<style lang="scss">
.header {
  height: 90rpx;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding-top: var(--status-bar-height);
  background-color: #fff;

  .left {
    position: absolute;
    left: 30rpx;

    .back-icon {
      font-size: 40rpx;
    }
  }

  .title {
    font-size: 32rpx;
    font-weight: bold;
  }

  .right {
    position: absolute;
    right: 30rpx;
  }
}
</style>
